package com.zxy.controller;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.zxy.model.*;
import com.zxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public String register(@RequestBody RegisterInfo registerInfo){

        return userService.register(registerInfo);
    }

    @PostMapping("/login")
    public String login(@RequestBody LoginInfo loginInfo){

        return userService.login(loginInfo);
    }

    @GetMapping("/permission")
    public List<String> getPermission() {
        return userService.getPermission();

    }

    @GetMapping("/list")
    public List<User> selectList(UserQuery query) {
        return userService.selectList(query);
    }

    @PostMapping("/editrole")
    public int addRole(@RequestBody UserRoles userRoles) {
        return userService.addRole(userRoles);
    }
}
